import 'package:equatable/equatable.dart';
import 'package:backend.purchases/domain/entities/yookassa_api/yookassa_api_money_amount.dart';

const kYookassaApiMoneyAmountValueKey = 'value';
const kYookassaApiMoneyAmountCurrencyKey = 'currency';

class YookassaApiMoneyAmountDto extends Equatable {
  const YookassaApiMoneyAmountDto._internal({
    required this.value,
    required this.currency,
  });

  final String value;
  final String currency;

  @override
  List<Object?> get props {
    return [
      value,
      currency,
    ];
  }

  factory YookassaApiMoneyAmountDto.fromJson(Map<String, dynamic> json) {
    return YookassaApiMoneyAmountDto._internal(
      value: json[kYookassaApiMoneyAmountValueKey],
      currency: json[kYookassaApiMoneyAmountCurrencyKey],
    );
  }

  factory YookassaApiMoneyAmountDto.fromEntity(YookassaApiMoneyAmount moneyAmount) {
    return YookassaApiMoneyAmountDto._internal(
      value: moneyAmount.value,
      currency: moneyAmount.currency,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      kYookassaApiMoneyAmountValueKey: value,
      kYookassaApiMoneyAmountCurrencyKey: currency,
    };
  }

  YookassaApiMoneyAmount toEntity() {
    return YookassaApiMoneyAmount(
      value: value,
      currency: currency,
    );
  }
}
